package com.yzw.mybatisutils.service;

import com.yzw.mybatisutils.model.Table;
import com.yzw.mybatisutils.uitls.FreemarkerUtil;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author：yzw
 * @Date：2017/11/29
 * @描述：
 */
public class FreemarkerService {
	public static boolean buildMapper(String templateName, String packageName, String path, Table table, String dbType) {
		Map<String, Object> params = new HashMap<String, Object>();
		String modelName = StringUtils.capitalize(DataBaseService.capColumnName(table.getTableName()));
		params.put("packageName", packageName);
		params.put("modelName", modelName);
		params.put("dbType", dbType);
		params.put("tableName", table.getTableName());
		params.put("columns", table.getColumns());
		return FreemarkerUtil.writeTemplate(templateName, params, path);
	}

	public static boolean buildModel(String templateName, String packageName, String path, Table table, List<String> packageList) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("packageName", packageName);
		params.put("tableComment", table.getTableComment() + "(" + table.getTableName() + ")");
		params.put("packageList", packageList);
		params.put("modelName", DataBaseService.capColumnName(table.getTableName()));
		params.put("columns", table.getColumns());
		return FreemarkerUtil.writeTemplate(templateName, params, path);
	}

	public static boolean buildCommon(String templateName, String packageName, String path, Table table) {
		Map<String, Object> params = new HashMap<String, Object>();
		String modelName = StringUtils.capitalize(DataBaseService.capColumnName(table.getTableName()));
		params.put("packageName", packageName);
		params.put("modelName", modelName);
		return FreemarkerUtil.writeTemplate(templateName, params, path);
	}
}
